#include "EpollServer.hpp"
#include <memory>
#include "Protocol.hpp"
using namespace std;
Response Calculate(const Request &req)
{
    Response res(0, 0);
    switch (req._op)
    {
    case '+':
        res._result = req._x + req._y;
        break;
    case '-':
        res._result = req._x - req._y;
        break;
    case '*':
        res._result = req._x * req._y;
        break;
    case '/':
        if (req._y == 0)
        {
            res._code = 1;
        }
        else
        {
            res._result = req._x / req._y;
        }
        break;
    case '%':
        if (req._y == 0)
        {
            res._code = 2;
        }
        else
        {
            res._result = req._x % req._y;
        }
        break;
    default:
        res._code = 3;
        break;
    }
    return res;
}




int main()
{
    unique_ptr<EpollServer> ptr(new EpollServer(Calculate));
    ptr->Init();
    ptr->Dispatcher();

    return 0;
}